<script setup>
import { ref } from 'vue'
import { getUserQrCode } from '@/api/jdb'
import useUserStore from '@/stores/modules/user'
import { showFailToast } from 'vant'
import { useRouter, useRoute } from 'vue-router'

const userStore = useUserStore()
const router = useRouter()
const route = useRoute()

const qrCodeUrl = ref('')

const onClickLeft = () => {
  router.back()
}

const init = () => {
  getUserQrCode().then((response) => {
    // console.log(response, 'getUserQrCode')
    qrCodeUrl.value = response.data.backQrcode
  })
}
init()
</script>

<template>
  <van-nav-bar title="我的二维码" left-arrow fixed placeholder @click-left="onClickLeft"/>
  <div class="qr-code-container">
    <img class="qr-code" :src="qrCodeUrl" />
  </div>
  <van-button class="save-btn" block type="success" loading-text="加载中...">长按图片保存到手机</van-button>
</template>

<style scoped>
.save-btn {
  width:355px;
  margin:51px auto 0;
  font-size:18px;
  font-weight:bold;
}
.qr-code-container {
  width: 98%;
  margin: 1%
}
.qr-code {
  margin-top:1%;
  width: 100% !important;
  text-align: center;
  height: auto !important;
  visibility: visible !important;
}
</style>
